﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using ShadowCommando.Game.Utilites;
namespace ShadowCommando.Game.Elements
{
    class Hero:Character
    {
        public Hero(int _step,LevelDifficulty _diff, HeroId _heroId):base(_step,_diff)
        {
            elementId = ElementId.Hero;
            heroId = _heroId;
            Life = ElementInfo.Default.heroLife;
            Armor = ElementInfo.Default.heroArmor;
            weapons.Add(new Weapon(step,BulletId.Laser,elementId,difficulty));
            weapons.Add(new Weapon(_step, BulletId.Bomb, elementId,difficulty));
            weapons.Add(new Weapon(_step, BulletId.Flechette, elementId,difficulty));  
            weapons.Add(new Weapon(_step, BulletId.HeavyLaser, elementId, difficulty));
            actualWeapon = weapons[actualWeaponCount];
            zIndex = 1;
        }   
        #region Items

        private HeroId heroId;
        
        private int actualWeaponCount=0;
        #endregion
        #region Properties
        /// <summary>
        /// HeroId
        /// </summary>
        public HeroId HeroId
        {
            get { return heroId; }
            set { heroId = value; }
        }
        #endregion
        #region Functions
        /// <summary>
        /// Ruch bohatera
        /// </summary>
        /// <param name="list">List zawierająca wcisniete przyciski</param>
        /// <returns></returns>
        public Point Move(List<Keys> list)
        {
            Point p = new Point(FakeX, FakeY);
            if (list.Contains(Keys.W) && list.Contains(Keys.D))
            {
                p.X += step;
                p.Y -= step;
            }
            else if (list.Contains(Keys.W) && list.Contains(Keys.A))
            {
                p.X -= step;
                p.Y -= step;
            }
            else if (list.Contains(Keys.S) && list.Contains(Keys.D))
            {
                p.X += step;
                p.Y += step;
            }
            else if (list.Contains(Keys.S) && list.Contains(Keys.A))
            {
                p.X -= step;
                p.Y += step;

            }
            else if (list.Contains(Keys.A) && list.Contains(Keys.D))
            {
            }
            else if (list.Contains(Keys.S) && list.Contains(Keys.W))
            {
            }
            else if (list.Contains(Keys.S))
            {

                p.Y += step;
            }
            else if (list.Contains(Keys.W))
            {
                p.Y -= step;
            }
            else if (list.Contains(Keys.D))
            {
                p.X += step;
            }
            else if (list.Contains(Keys.A))
            {
                p.X -= step;
            }
            return p;
        }
        /// <summary>
        /// Podkładanie bomby
        /// </summary>
        /// <returns></returns>
        public Bullet PlantBomb()
        {
            var bomb = (from VAR in weapons where VAR.BulletId   == BulletId.Bomb select VAR).First();
            if(bomb.BulletCount<=0)
            {
                return null;
            }
            bomb.BulletCount--;
            Point p=new Point();
            p.X    = FakeX + this.width/2;
            p.Y = FakeY + this.Height/2;
            return bomb.Shot(p, p, cos, sin);
        }
        /// <summary>
        /// Zmiana aktualnej broni
        /// </summary>
        public new void ChangeWeapon()
        {
            Weapon weapon = weapons[0];
            weapons.Remove(weapon);
            weapons.Add(weapon);
            actualWeapon = weapons[0];
        }
        /// <summary>
        /// Strzał 
        /// </summary>
        /// <param name="p1">Cel</param>
        /// <returns>Pocisk </returns>
        public new Bullet Shot(Point p1)
        {
            if (actualWeapon.BulletCount != 0)
            {
                if(actualWeapon.BulletId!=BulletId.Laser)
                actualWeapon.BulletCount--;
                Bullet b= actualWeapon.Shot(p1, new Point(FakeX, FakeY), cos, sin);
                if (b == null)
                    return null;
                b.Demage = (int)( atackFactor*b.Demage);
                return b;
            }
            return null;
        }
        #endregion
    }
}
